<template>
<div class="base-container">
  <t-divider style="font-size: 20px">评审组信息</t-divider>
  <t-form labelWidth="150px" :data="formData" ref="form"  :colon="true">
    <t-row style="row-gap: 10px">
      <t-col :span="6">
        <t-form-item label="分组名" name="name">
          {{formData.name}}
        </t-form-item>
      </t-col>

<!--      <t-col :span="6">-->
<!--        <t-form-item label="学科分类" name="subjectClassification">-->
<!--          {{formData.subjectClassification.join(",") | filterByDict(dict.type.subject_classification) }}-->
<!--        </t-form-item>-->
<!--      </t-col>-->
      <t-col :span="6">
        <t-form-item label="评审业务类型" name="reviewType">
          {{ formData.reviewType | filterByDict(dict.type.kjsf_review_type) }}
        </t-form-item>
      </t-col>
      <t-col :span="6">
        <t-form-item label="分组说明" name="note">
          {{formData.note}}
        </t-form-item>
      </t-col>
      <t-col :span="6">
        <t-form-item label="专家评审开始时间" name="startReviewDate">
          {{formData.startReviewDate}}
        </t-form-item>
      </t-col>
      <t-col :span="6">
        <t-form-item label="专家评审截止时间" name="endReviewDate">
          {{formData.endReviewDate}}
        </t-form-item>
      </t-col>
    </t-row>
  </t-form>
  <t-divider style="font-size: 20px">本组评审项目</t-divider>
  <t-table
    rowKey="id"
    :data="projectList"
    :columns="projectColumns"
    :bordered="true"
    :hover="true"
  >
    <template #teamLeaderOpinion="{row}">
      <t-tag theme="success" variant="light" v-if="row.teamLeaderOpinion">
        是
      </t-tag>
      <t-tag theme="danger" variant="light" v-else>
        否
      </t-tag>
    </template>
    <template #[`project.adviceFunding`]="{ row }">
      {{ row.project.adviceFunding }}万元
    </template>
    <template #[`project.projectName`]="{ row }">
      <t-link @click="dialog.header=row.project.projectName;dialog.objId=row.project.id;dialog.editOpen=false;dialog.open_project_detail=true" hover="color" theme="primary">{{row.project.projectName}}</t-link>
    </template>
<!--    <template #[`project.subjectClassification`]="{row}">-->
<!--      {{ row.project?.subjectClassification | filterByDict(dict.type.subject_classification) }}-->
<!--    </template>-->
    <template #[`project.projectType`]="{row}">
      {{ row.project?.projectType | filterByDict(dict.type.project_type) }}
    </template>
    <template #op="{row}">
      <t-button    @click="openReviewDetail(row)" size="small" variant="text"
                 class="t-button-link">
        <t-icon name="root-list" slot="icon"/>
        专家评审详情
      </t-button>
      <t-button v-if="formData.reviewType === '2'" @click="dialog.header=row.project.projectName;dialog.objId=row.project.id;dialog.editOpen=false;dialog.open_detail=true" size="small" variant="text" class="t-button-link">
        <t-icon name="info-circle" slot="icon"/>
        实施方案详情
      </t-button>
      <t-button @click="dialog.teamId=row.teamId;dialog.objId=row.id;dialog.projectNum=row.project.projectNum;dialog.projectName=row.project.projectName;dialog.open_leader_project_approval=true" size="small" variant="text" class="t-button-link">
        <t-icon name="edit-1" slot="icon" />
        综合评审
      </t-button>
    </template>
  </t-table>
  <t-divider style="font-size: 20px">本组评审专家</t-divider>
  <t-table
    rowKey="id"
    :data="expertList"
    :columns="expertColumns"
    :bordered="true"
    :hover="true"
  >
    <template #[`experts.sysUser.nickName`]="{ row }">
      <t-badge v-if="row.teamLeader==='1' && !['1'].includes(formData.reviewType)" count="组长" :offset="[-10, -6]">
        <t-link style="margin-right: 0" @click="dialog.objId=row.experts.id;dialog.idCard=row.experts.sysUser.idCard;dialog.header=row.experts.sysUser.nickName;dialog.open_expert_detail=true" hover="color" theme="primary"> {{ row.experts.sysUser.nickName }}</t-link>
      </t-badge>
      <template v-else>
        <t-link  @click="dialog.objId=row.experts.id;dialog.idCard=row.experts.sysUser.idCard;dialog.header=row.experts.sysUser.nickName;dialog.open_expert_detail=true" hover="color" theme="primary"> {{ row.experts.sysUser.nickName }}</t-link>
      </template>
    </template>
    <template #[`experts.sysUser.duty`]="{ row }">
      <div v-if="['99999',''].includes(row.experts.sysUser?.profTit)">
        {{ row.experts.sysUser?.duty }}
      </div>
      <div v-else>
        {{ row.experts.sysUser?.duty }}/{{ row.experts.sysUser?.profTit | filterByDict(dict.type.prof_tit) }}
      </div>
    </template>
    <template #[`experts.sysUser.education`]="{ row }">
      {{ row.experts.sysUser?.education | filterByDict(dict.type.education) }}/{{ row.experts.sysUser?.degree | filterByDict(dict.type.degree) }}
    </template>
    <template #[`sendMsg`]="{ row }">
      <t-tag v-if="row.sendMsg==='1'" theme="success" variant="light">发送成功</t-tag>
      <t-tag v-else-if="row.sendMsg==='0'" theme="danger" variant="light">发送失败</t-tag>
      <t-tag v-else theme="warning" variant="light">未发送</t-tag>/<t-tag v-if="row.joinType==='1'" theme="success" variant="light">参加</t-tag>
      <t-tag v-else-if="row.joinType==='0'" theme="danger" variant="light">不参加</t-tag>
      <t-tag v-else theme="warning" variant="light">未回复</t-tag>
    </template>
  </t-table>
  <expert-review-list :rowId="dialog.rowId" :expert-leader="dialog.expertLeader" :teamId="dialog.teamId" :objId="dialog.objId" :reviewType="formData.reviewType" :projectName="dialog.projectName" :visible.sync="dialog.open_review_list"
                      v-if="dialog.open_review_list"></expert-review-list>
  <project-detail-dialog :header="dialog.header" tab-default-value="2" :objId="dialog.objId" :visible.sync="dialog.open_project_detail" v-if="dialog.open_project_detail"></project-detail-dialog>
  <implement-plan-detail-dialog :header="dialog.header"  :project-id="dialog.objId" :visible.sync="dialog.open_detail" v-if="dialog.open_detail"></implement-plan-detail-dialog>

  <expert-leader-project-approval @reload="teamProjectGet" :projectNum="dialog.projectNum" :teamId="dialog.teamId" :reviewType="formData.reviewType" :projectName="dialog.projectName" :objId="dialog.objId" :visible.sync="dialog.open_leader_project_approval" v-if="dialog.open_leader_project_approval"></expert-leader-project-approval>
  <expert-detail-dialog :header="dialog.header" :obj-id="dialog.objId" :id-card="dialog.idCard" :visible.sync="dialog.open_expert_detail"
                        v-if="dialog.open_expert_detail"></expert-detail-dialog>
</div>
</template>

<script>
import ProjectDetailDialog from "../project/components/project-detail-dialog.vue";
import ExpertReviewList from "./components/expert-review-list.vue";
import ExpertLeaderProjectApproval from "./components/expert-leader-project-approval.vue";
import ExpertDetailDialog from "../../zjk/expert/components/expert-detail-dialog.vue";
import ImplementPlanDetailDialog from "../implement/components/implement-plan-detail-dialog.vue";

export default {
  name: "review-group-project",
  dicts: ['kjsf_review_type','project_type', 'education', 'degree', 'prof_tit'],
  components:{
    ProjectDetailDialog,
    ImplementPlanDetailDialog,
    ExpertReviewList,
    ExpertLeaderProjectApproval,
    ExpertDetailDialog
  },
  data(){
    return {
      dialog:{
        parentId: 0,
        objId: 0,
        teamId: 0,
        projectId: 0,
        editOpen:false,
        open_add_edit: false,
        header: "",
        open_detail:false,
        open_review_list: false,
        open_select_project: false,
        open_select_expert: false,
        open_project_approval: false,
        projectName:'',
        open_project_detail: false,
        open_review_standard: false,
        open_plan_detail: false,
        open_acceptance_detail: false,
        open_leader_project_approval: false,
        open_expert_detail: false,
        reviewType: '',
        expertLeader: {},
        rowId: null,
        projectNum: '',
        idCard: ''
      },
      objId: null,
      teamId: null,
      projectList: [],
      projectColumns: [
        {colKey: 'project.projectName', title: '项目名称',align: "center", width: 180},
        {colKey: 'project.adviceFunding', title: '投入经费', align: "center", width: 100},
        // {colKey: 'project.projectCategoryName', title: '计划类别',align: "center"},
        // {colKey: 'project.subjectClassification', title: '学科分类',align: "center"},
        // {colKey: 'project.projectType', title: '项目类型',align: "center"},
        {colKey: 'project.projectLeader.name', title: '负责人',align: "center", width: 100},
        {colKey: 'project.sysDept.deptName', title: '承担单位',align: "center", width: 180},
        {colKey: 'teamLeaderOpinion', title: '是否综合评审',align: "center", width:120},
        // {colKey: 'project.attributeDeptName', title: '归口单位',align: "center"},
        {
          colKey: 'op',
          title: '操作',
          align: "center",
          width: 130
        },
      ],
      expertList:[],
      expertColumns: [
        {colKey: 'experts.sysUser.nickName', title: '专家姓名',align: "center"},
        {colKey: 'experts.age', title: '年龄', align: 'center', width: 80},
        {colKey: 'experts.sysUser.dept.deptName', title: '所在单位',align: "center", width: 180},
        {colKey: 'experts.sysUser.phonenumber', title: '手机号',align: "center", width: 130},
        {colKey: 'experts.sysUser.duty', title: '职务/职称',align: "center"},
        // { colKey: 'experts.declareDeptName', title: '部门', },
        {colKey: 'experts.recommendMajorName', title: '组别',align: "center", width: 120},
        // {colKey: 'experts.sysUser.majorName', title: '专业',align: "center"},
        {colKey: 'experts.sysUser.majorNowName', title: '现从事专业',align: "center"},
        {colKey: 'experts.sysUser.education', title: '学历/学位',align: "center"},
        // {colKey: 'experts.sysUser.degree', title: '学位',align: "center"},
        {colKey: 'sendMsg', title: '短信通知/是否参加',align: "center", width: 160},
        // {colKey: 'experts.joinType', title: '是否参加',align: "center"},
        // {colKey: 'experts.joinReviewTimes', title: '参与评审次数',align: "center"},
        // {colKey: 'experts.joinProjectTimes', title: '参与项目次数',align: "center"},

        // {colKey: 'experts.phoneNumber', title: '联系方式',align: "center"},
        // {
        //   colKey: 'op',
        //   title: '操作',
        //   width: 130,
        //   align: "center",
        // },
      ],
      formData: {
        id: '',
        reviewType: '',
        name: '',// 分组名
        note: '',
        subjectClassification: [],
        planName: ""
      },
    }
  },
  created() {
    const teamId = this.$route.params && this.$route.params.taskId;
    if (!teamId) {
      this.$message.error("评审组id丢失返回");
      this.$router.push({
        path: "/zjk/review/review-group-opinion-my",
        query: {
          tabValue: '2'
        }
      });
    }
    this.teamId = teamId;
    this.getObj();
    this.teamProjectGet();
    this.teamExpertGet();
  },
  methods:{
    openReviewDetail(row){
      // dialog.objId=row.project.id;dialog.teamId=formData.id;dialog.projectName=row.project.projectName;dialog.open_review_list=true

      this.dialog.objId = row.project.id;
      this.dialog.teamId = this.formData.id;
      this.dialog.projectName = row.project.projectName;
      // 先判断有没有设置专家组长
      let expertLeader = null;
      const obj = this.expertList.find((val) => val.teamLeader === '1')
      if (obj) {
        expertLeader = {
          id: obj.experts.userId,
          nickName: obj.experts.sysUser.nickName
        }
      }
      this.dialog.expertLeader = expertLeader;
      this.dialog.rowId = row.id;
      this.dialog.open_review_list = true;
    },
    getObj(){
      this.$api.kjsf.review.teamGet(this.teamId).then((response) => {
        response.data.subjectClassification = response.data.subjectClassification?response.data.subjectClassification.split(",").filter(item=> item !== ''):[]
        Object.assign(this.formData, response.data);
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    // 本组申报项目列表
    teamProjectGet() {
      this.$api.kjsf.review.teamProjectGet(this.teamId).then((response) => {
        this.projectList = response.data;
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    // 查专家列表
    teamExpertGet() {
      this.$api.kjsf.review.teamExpertGet(this.teamId).then((response) => {
        this.expertList = response.data;
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
  }
}
</script>

<style scoped>

</style>
